package com.shop.technicalservice.dao.role.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.rjb.dao.RolesDAOTest;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.shop.technicalservice.dao.role.RolesDao;
import com.shop.technicalservice.model.role.Roles;

/**
 * A data access object (DAO) providing persistence and search support for Roles
 * entities. Transaction control of the save(), update() and delete() operations
 * can directly support Spring container-managed transactions or they can be
 * augmented to handle user-managed Spring transactions. Each of these methods
 * provides additional information for how to configure it for the desired type
 * of transaction control.
 * 
 * @see org.rjb.pojo.RolesDto
 * @author MyEclipse Persistence Tools
 */

public class RolesDaoImpl extends HibernateDaoSupport implements RolesDao {
	private static final Log log = LogFactory.getLog(RolesDaoImpl.class);
	// property constants
	public static final String ROLE_NAME = "roleName";

	protected void initDao() {
		// do nothing
	}

	public Roles save(Roles transientInstance)  throws Exception{
		log.debug("saving Roles instance");
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
			return transientInstance;
	}

	public void delete(Roles persistentInstance)  throws Exception{
		log.debug("deleting Roles instance");
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
			 
	}

	public Roles findById(java.lang.Integer id)  throws Exception{
		log.debug("getting Roles instance with id: " + id);
			Roles instance = (Roles) getHibernateTemplate().get(
					"org.rjb.Roles", id);
			return instance;
	}

	public List findByExample(Roles instance)  throws Exception{
		log.debug("finding Roles instance by example");
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
	}

	public List findByProperty(String propertyName, Object value)  throws Exception{
		log.debug("finding Roles instance with property: " + propertyName
				+ ", value: " + value);
			String queryString = "from Roles as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
	}

	public List findByRoleName(Object roleName)  throws Exception{
		return findByProperty(ROLE_NAME, roleName);
	}

	public List findAll()  throws Exception{
		log.debug("finding all Roles instances");
			String queryString = "from Roles";
			return getHibernateTemplate().find(queryString);
	}

	public Roles merge(Roles detachedInstance)  throws Exception{
		log.debug("merging Roles instance");
			Roles result = (Roles) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
	}

	public void attachDirty(Roles instance)  throws Exception{
		log.debug("attaching dirty Roles instance");
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
	}

	public void attachClean(Roles instance)  throws Exception{
		log.debug("attaching clean Roles instance");
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
	}

	public static RolesDAOTest getFromApplicationContext(ApplicationContext ctx) {
		return (RolesDAOTest) ctx.getBean("RolesDAO");
	}
}